package com.ruoyi.web.controller.tzzl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.tzzl.domain.WzBalanceChangeRecord;
import com.ruoyi.tzzl.domain.WzOrder;
import com.ruoyi.tzzl.domain.vo.QueryVo;
import com.ruoyi.tzzl.service.IWzOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author by caoyong
 * @date 2022/11/17
 **/
@RestController
@RequestMapping("/tzzl/order")
public class WzOrderController extends BaseController {

    @Autowired
    private IWzOrderService wzOrderService;

    /**
     * 查询订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(QueryVo wzOrder)
    {
        startPage();
        List<WzOrder> list = wzOrderService.selectWzOrderList(wzOrder);
        return getDataTable(list);
    }

    /**查看订单详情*/
    @GetMapping("/orderDetails")
    public AjaxResult orderDetails(String orderNumber){
        return AjaxResult.success(wzOrderService.getByOrderNumber(orderNumber));
    }

    /**
     * 查看订单数据
     * */
    @GetMapping("/orderData")
    public AjaxResult orderData(){
        return AjaxResult.success(wzOrderService.orderData());
    }

    /**
     * 查询订单交易金额
     * */
    @GetMapping("/orderAmount")
    public TableDataInfo orderAmount(Long type){
        startPage();
       List<WzOrder> list = wzOrderService.orderAmount(type);
        return getDataTable(list) ;
    }

    /**
     * 查询总成交易金额和当日成交金额
     * */
    @GetMapping("/sumAmount")
    public AjaxResult sumAmount(){
        return AjaxResult.success(wzOrderService.sumAmount());
    }

    /**提交订单*/
    @PostMapping("/addOrder")
    public AjaxResult addOrder(@RequestBody WzOrder wzOrder ){
        return AjaxResult.success(wzOrderService.addOrder(wzOrder));
    }


    /**
     * 删除订单
     * */
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids){
        for (int i = 0; i < ids.length; i++) {
            wzOrderService.removeById(ids[i]);
        }
        return AjaxResult.success();
    }

    /**
     * 查看订单详情
     * */
    @GetMapping("/details")
    public AjaxResult details(Long id){
        return AjaxResult.success(wzOrderService.getById(id));
    }

    /**
     * 查询月订单交易记录
     * */
    @GetMapping("/tradingOrder")
    public AjaxResult tradingOrder(){
        return AjaxResult.success(wzOrderService.yearMonthRecord());
    }

    /**
     * 查询用户分销订单记录
     * */
    @GetMapping("/orderRecord")
    public AjaxResult orderRecord(WzBalanceChangeRecord wzBalanceChangeRecord){
        return AjaxResult.success(wzOrderService.orderRecord(wzBalanceChangeRecord));
    }

    /**
     * 查看邀约订单
     * */
    @GetMapping("/invitationOrder")
    public AjaxResult invitationOrder(WzOrder wzOrder){
        return AjaxResult.success(wzOrderService.userInvitationOrder(wzOrder.getWid()));
    }

    /**
     * 确认邀约订单
     * */
    @PostMapping("/confirmOrder")
    public AjaxResult confirmOrder(WzOrder wzOrder){
        return AjaxResult.success(wzOrderService.confirmOrder(wzOrder));
    }

    /**会员管理记录列表*/
    @GetMapping("/membershipManagement")
    public TableDataInfo membershipManagement(WzOrder wzOrder){
        startPage();
        return getDataTable(wzOrderService.membershipManagement(wzOrder));
    }

    /**查看是否与该用户聊过天*/
    @GetMapping("/chat")
    public AjaxResult chat(Long wid,Long beUserId){
        return AjaxResult.success(wzOrderService.doesExistChat(wid ,beUserId));
    }


}
